package com.dc.connectionfactory;

import java.sql.*;
/**
 * l锟接癸拷锟斤拷,锟斤拷4锟结供锟斤拷菘锟絣锟接和关憋拷锟斤拷菘锟斤拷锟皆�
 * 锟斤拷锟斤拷模锟斤拷要l锟斤拷锟斤拷菘舛�锟斤拷锟斤拷锟斤拷锟�
 * */
public class ConnectionFactory {
	
	private static final String DRIVER = "com.mysql.jdbc.Driver";
	private static final String URL = "jdbc:mysql://127.0.0.1:3306/geree";
	private static final String USERNAME = "root";
	private static final String PASSWORD = "root";
	
	/**
	 * 锟斤拷态锟斤拷锟斤拷锟结供l锟接讹拷锟斤拷
	 * */
	public static Connection getConnection(){
		try{
			Class.forName(DRIVER);
			return DriverManager.getConnection(URL,USERNAME,PASSWORD);
		}catch(Exception ex){
			System.out.println("链接数据库出错");
			ex.printStackTrace();
			return null;
		}
	}
	
	/**
	 * 锟斤拷态锟斤拷锟斤拷锟截憋拷锟斤拷菘锟斤拷锟皆�
	 * */
	public static void close(Connection con,Statement stm,ResultSet rs){
		try{
			if(rs != null) rs.close();
			if(stm != null) stm.close();
			if(con != null) con.close();
		}catch(Exception ex){
		}
	}

}
